package org.dromara.comm_lhz.controller;

import lombok.AllArgsConstructor;
import org.dromara.comm_lhz.entity.AsGridMapTableEntity;
import org.dromara.comm_lhz.entity.AsGridStaffEntity;
import org.dromara.comm_lhz.service.AsGridHService;
import org.dromara.comm_lhz.service.AsGridStaffHService;
import org.dromara.comm_lhz.util.QiniuUtil;
import org.dromara.comm_lhz.util.Result;
import org.springframework.web.bind.annotation.*;


/**
 * 网格信息控制器
 */
@RestController
@RequestMapping("/grid")
@AllArgsConstructor
public class AsGridHController {

    QiniuUtil qiniuUtil;
    private AsGridHService asGridHService;
    private AsGridStaffHService asGridStaffHService;

    /**
     * 树形结构查询网格列表
     *
     * @param name 网格名称，可选参数
     * @return 结果对象，包含查询结果和消息
     */
    @GetMapping("/selGridList")
    public Result selGridList(String name) {
        return Result.success("查询成功", asGridHService.findTree(name));
    }

    /**
     * 添加网格信息
     *
     * @param asGridMapTableEntity 网格信息实体
     */
    @PostMapping("/addGridInfo")
    public void addGrid(@RequestBody AsGridMapTableEntity asGridMapTableEntity) {
        asGridHService.save(asGridMapTableEntity);
    }

    /**
     * 修改网格信息
     *
     * @param asGridMapTableEntity 网格信息实体
     * @return 结果对象，包含操作结果和消息
     */
    @PostMapping("/updateGridInfo")
    public Result updateGrid(@RequestBody AsGridMapTableEntity asGridMapTableEntity) {
        if (asGridHService.updateById(asGridMapTableEntity)) {
            return Result.success("修改成功");
        } else {
            return Result.error("修改失败");
        }
    }

    /**
     * 删除网格信息
     *
     * @param id 网格ID
     * @return 结果对象，包含操作结果和消息
     */
    @PostMapping("/deleteGridInfo")
    public Result deleteGrid(@RequestParam("id") Long id) {
        if (asGridHService.removeById(id)) {
            return Result.success("删除成功");
        } else {
            return Result.error("删除失败");
        }
    }

    /**
     * 查询网格详细信息
     *
     * @param id 网格ID
     * @return 结果对象，包含查询结果和消息
     */
    @GetMapping("/selGridInfo")
    public Result selGridInfo(Long id) {
        return Result.success("查询成功", asGridHService.selGridInfo(id));
    }



    /**
     * 添加网格员信息
     * 该方法用于将网格员的信息保存到数据库中
     * @param asGridStaffEntity 包含网格员详细信息的实体对象
     */
    @PostMapping("/addGridStaffInfo")
    public void addGridStaffInfo(@RequestBody AsGridStaffEntity asGridStaffEntity) {
        asGridStaffHService.save(asGridStaffEntity);
    }

    /**
     * 更新网格员信息
     *
     * @param asGridStaffEntity 包含更新后网格信息的实体对象
     */
    @PostMapping("/updateGridStaffInfo")
    public void updateGridStaffInfo(@RequestBody AsGridStaffEntity asGridStaffEntity) {
        asGridStaffHService.updateById(asGridStaffEntity);
    }

    /**
     * 删除网格员信息
     *
     * @param id 网格ID
     */
    @DeleteMapping("/deleteGridStaffInfo")
    public void deleteGridStaffInfo(@RequestParam("id") Long id) {
        asGridStaffHService.removeById(id);
    }
}
